package com.cnsuning.jobtool.jobtools;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class TableCountTest {
    @Test
    public void test()
    {
        String fileName = "E:\\suning_files\\query_isexists_20200106_20200106.txt";
        String targetFileName = "E:\\suning_files\\query_isexists_modify.txt";
        File file  = new File(fileName);
        File targetFile = new File(targetFileName);
        if (targetFile.exists()) targetFile.delete();
        Map<String,Integer> resultMap = new HashMap<>();
        try {
            FileReader fr = new FileReader(file);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                String[] split = str.split(",");
                if (split != null && split.length> 0){
                    String tableName = split[0];
                    Integer count = resultMap.get(tableName);
                    if (count == null)
                    {
                        count = 0;
                    }
                    count++;
                    resultMap.put(tableName,count);
                    if (tableName.equals("SO_RET_PAY") ||
                            tableName.equals("SO_TIMING_EVENT_CONTROL")||
                            tableName.equals("SO_SALES_ORDER_MAIN_INF")||
                            tableName.equals("SO_PAY_INFO")||
//                            tableName.equals("SO_ST_ORDI_STATUS")||
                            tableName.equals("SO_O2O_RET_RELATION_ITEMS_INFO")||
                            tableName.equals("SO_ORDI_EXTENDS_INFO")||
                            tableName.equals("SO_ORDI")||
                            tableName.equals("INF_SAP_RTNCHG")||
                            tableName.equals("SO_DELI_PENDING")||
                            tableName.equals("SO_ORDI_DELIVERY")||
                            tableName.equals("SO_ARREARS_RELATE_INFO")){
                        FileUtils.writeStringToFile(targetFile,str+"\n",true);
                    }
                }

            }
            bf.close();
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (Map.Entry<String,Integer> entry: resultMap.entrySet())
        {
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
    }
}
